package hao.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/response")
public class ResponseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // -- 一般不设置`
        //1.设置响应状态码--模拟成功之后响应{不推荐设置}
        resp.setStatus(HttpServletResponse.SC_ACCEPTED);

        //2.设置响应头
        resp.setContentType("text/html;charset=utf-8");
        //设置响应编码和相应数据类型 注意: text/html;得写在前面
        resp.setHeader("Content-Type","text/html;charset=utf-8");

        //3.设置响应数据
        String name = req.getParameter("name");
        resp.getWriter().write("<h1>Hello Tom</h1>" + name);
        //framework 意思是框架
    }
}
